package com.asr.controller;

import com.asr.config.AsrProperties;
import com.asr.dto.ModelInfo;
import com.asr.model.ApiResponse;
import com.asr.service.ModelService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/models")
@RequiredArgsConstructor
public class ModelController {
    
    private final ModelService modelService;
    private final AsrProperties asrProperties;
    
    /**
     * 获取所有可用的 ASR 模型
     */
    @GetMapping("/asr")
    public ApiResponse<List<ModelInfo>> getAsrModels() {
        List<ModelInfo> models = modelService.getAvailableAsrModels();
        return ApiResponse.success(models);
    }
    
    /**
     * 获取指定 ASR 模型配置
     */
    @GetMapping("/asr/{modelId}")
    public ApiResponse<ModelInfo> getAsrModel(@PathVariable String modelId) {
        ModelInfo model = modelService.getAsrModelInfo(modelId);
        if (model == null) {
            return ApiResponse.error(404, "模型不存在");
        }
        return ApiResponse.success(model);
    }
    
    /**
     * 获取说话人模型配置
     */
    @GetMapping("/speaker")
    public ApiResponse<AsrProperties.Speaker> getSpeakerModel() {
        AsrProperties.Speaker speaker = modelService.getSpeakerModel();
        return ApiResponse.success(speaker);
    }
    
    /**
     * 获取默认配置
     */
    @GetMapping("/defaults")
    public ApiResponse<AsrProperties.Default> getDefaultConfig() {
        AsrProperties.Default defaults = asrProperties.getDefaultConfig();
        return ApiResponse.success(defaults);
    }
    
    /**
     * 获取支持的语言列表
     */
    @GetMapping("/languages")
    public ApiResponse<List<Map<String, String>>> getSupportedLanguages() {
        List<Map<String, String>> languages = List.of(
            Map.of("code", "auto", "name", "自动检测"),
            Map.of("code", "zh", "name", "中文（国语）"),
            Map.of("code", "yue", "name", "粤语")
        );
        return ApiResponse.success(languages);
    }
}
